from bs4 import BeautifulSoup
from lxml import etree
import requests
import re


def get_connection(url):
    return requests.get(url)


def get_data(url):
    return get_connection(url).text


def spider(url):
    data = get_data(url)
    if data:
        print('成功')
        print(data)
    else:
        print('失败')
    data_list = data_deal(data)
    show_data(data_list)


def data_deal(data):
    data_list = re.findall(img_reg(), data)
    return data_list


def show_data(data_list):
    for data in data_list:
        print(data)


def img_reg():
    return '<img src="(.*?)" alt=.*?>'


if __name__ == '__main__':
    url = input('请输入您要爬取的网站网址：\n')
    spider(url)


soup = BeautifulSoup(get_connection(url).content,'html.parser')
print(soup.find_all('a').__getattr__('href'))
print()
